;; supercollider/server-status.scm - (c) rohan drape, 2003-2005

;; Make a fixed width string from the server status information list.

(define (server-status-format status)
  (apply 
   string-append
   (map (lambda (what value size after)
	  (format "~a: ~a~a" 
		  what 
		  (string-pad-right (number->string value) size) after))
	(list "UGens" "Synths" "Groups" "SynthDefs" 
	      "Average-CPU" "Peak-CPU" "Nominal-SR" "Actual-SR")
	status
	(list 3 3 3 3 4 4 8 8)
	(list " " " " " " " " "% " "% " " " ""))))

;; Install a receiver to print a status message, request a status
;; message, print the message, and uninstall the printer.

(define (server-print-status)
  (define (printer packet)
    (display* (server-status-format (cddr packet)))
    (osc-receiver-unregister printer))
  (osc-receiver-register "status.reply" printer)
  (-> "/status"))
